/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.People;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class PeopleFetcher implements Fetcher<People>
{
    @Override
    public People fetch( ResultSet ps ) throws Exception
    {
        People p = new People();
        
        p.setId( ps.getInt( 1 ) );
        p.setAddressId( ps.getInt( 2 ) );
        p.setName( ps.getString( 3 ) );
        p.setEmail( ps.getString( 4 ) );
        p.setCpf( ps.getString( 5 ) );
        p.setRg( ps.getString( 6 ) );
        p.setBirthday( ps.getDate( 7 ) );
        p.setGender( ps.getShort( 8 ) );
        p.setFixPhone( ps.getString( 9 ) );
        p.setMobilePhone( ps.getString( 10 ) );
        p.setState( ps.getShort( 11 ) );
        
        return p;
    }

    @Override
    public void insert( People value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_peoples" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getAddressId() );
        ps.setString( 3, value.getName() );
        ps.setString( 4, value.getEmail() );
        ps.setString( 5, value.getCpf() );
        ps.setString( 6, value.getRg() );
        ps.setDate( 7, value.getBirthday() );
        ps.setShort( 8, value.getGender() );
        ps.setString( 9, value.getFixPhone() );
        ps.setString( 10, value.getMobilePhone() );
        ps.setShort( 11, value.getState() );
    }

    @Override
    public void update( People value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getAddressId() );
        ps.setString( 2, value.getName() );
        ps.setString( 3, value.getEmail() );
        ps.setString( 4, value.getCpf() );
        ps.setString( 5, value.getRg() );
        ps.setDate( 6, value.getBirthday() );
        ps.setShort( 7, value.getGender() );
        ps.setString( 8, value.getFixPhone() );
        ps.setString( 9, value.getMobilePhone() );
        ps.setShort( 10, value.getState() );
        ps.setInt( 11, value.getId() );
    }
    
}
